package com.jlnk.androidfmc.view;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.jlnk.androidfmc.R;
import com.jlnk.androidfmc.fragment.FollowFragment;
import com.jlnk.androidfmc.fragment.LatestFragment;

public class NyqActivity extends AppCompatActivity {

    private DrawerLayout drawerLayout;
    private FrameLayout frameLayoutContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_nyq);

        drawerLayout = findViewById(R.id.drawer_layout);
        frameLayoutContent = findViewById(R.id.frameLayoutContent);

        // 初始化默认显示的Fragment
        showFragment(new FollowFragment());

        // 设置按钮点击事件
        TextView textViewFollow = findViewById(R.id.textViewFollow);
        textViewFollow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showFragment(new FollowFragment());
            }
        });

        TextView textViewLatest = findViewById(R.id.textViewLatest);
        textViewLatest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showFragment(new LatestFragment());
            }
        });

        // 初始化“我的”按钮中的 ImageView 和 TextView（假设它们在同一个 RelativeLayout 中）
        ImageView imageViewMyIcon = findViewById(R.id.btnMy);
        TextView textViewMy = findViewById(R.id.textViewMy);


        // 设置“我的”按钮的点击事件
        imageViewMyIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到“我的”页面的逻辑
                Intent intent = new Intent(NyqActivity.this, MyNyq.class);
                startActivity(intent);
            }
        });

        // 初始化“发农友圈”按钮
        ImageButton issueButton = findViewById(R.id.btnRelease);
        issueButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到发农友圈页面的逻辑
                Intent intent = new Intent(NyqActivity.this, NyqPost.class);
                startActivity(intent);
            }
        });
    }

    private void showFragment(Fragment fragment) {
        // 使用FragmentManager来替换Fragment
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.frameLayoutContent, fragment);
        fragmentTransaction.commit();
    }
}
